package io.karim.materialtabs.sample;

import ohos.agp.components.*;
import ohos.app.Context;

/**
 * SampleFragment
 *
 * @author hal
 * @since 2021/7/20
 */
public class SampleFragment extends StackLayout {

    private Text mTextView;

    public SampleFragment(Context context) {
        this(context, null);
    }

    public SampleFragment(Context context, AttrSet attrSet) {
        this(context, attrSet, null);
    }

    public SampleFragment(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        initView();
    }

    public static SampleFragment newInstance(int position, Context context) {
        SampleFragment sampleFragment = new SampleFragment(context);
        sampleFragment.setText(position);
        return sampleFragment;
    }

    private void setText(int position) {
        mTextView.setText("Fragment #" + position);
    }

    private void initView() {
        Component component = LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_fragment_card, this, false);
        addComponent(component);
        mTextView = (Text) component.findComponentById(ResourceTable.Id_textView);
    }
}
